package cn.kshost.zqyg.user.controller;

import cn.kshost.zqyg.model.entity.user.UserAddress;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import cn.kshost.zqyg.user.service.UserAddressService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/user/userAddress/auth")
public class UserAddressController {
    @Autowired
    private UserAddressService userAddressService;

    @Operation(summary = "获取用户地址列表")
    @GetMapping("/findUserAddressList")
    public Result findUserAddressList() {
        List<UserAddress> userAddressList =  userAddressService.findUserAddressList();
        return Result.build(userAddressList, ResultCodeEnum.SUCCESS);

    }

    @Operation(summary = "根据地址id获取地址信息")
    @GetMapping("/getUserAddress/{id}")
    public Result<UserAddress> findUserAddressById(@PathVariable("id") Long id) {

        UserAddress userAddress =  userAddressService.findUserAddressById(id);
        return Result.build(userAddress, ResultCodeEnum.SUCCESS);

    }
}
